package yxy.game.pm2.active.command.sdk.weixin.onlinegift;

import yxy.apple.logger.Logger;
import yxy.cherry.game.base.message.MessageEmitterHandler;
import yxy.cherry.game.base.message.annotation.MessageSource;
import yxy.cherry.game.base.message.annotation.MessageType;
import yxy.game.pm2.Result;
import yxy.game.pm2.active.module.sdk.weixin.ActiveModule_在线礼包;
import yxy.game.pm2.command.Command;
import yxy.game.pm2.message.SdkActiveMessage;
import yxy.game.pm2.message.SdkActiveMessage.WeiXinOnlineDotRequest;

/**
 * 在线礼包
 * @author Dell
 *
 */
@MessageType(proto = Command.WeiXinOnlineDot, classtype = SdkActiveMessage.WeiXinOnlineDotRequest.class)
public class CMD_Active_在线礼包_Dot extends Command<WeiXinOnlineDotRequest> {
	
	private static final Logger logger = Logger.create(CMD_Active_在线礼包_Dot.class);
	
	@Override
	public void execute(MessageSource messageSource, WeiXinOnlineDotRequest request) throws Exception {
		String pcode = messageSource.getTag();
		SdkActiveMessage.WeiXinOnlineDotResponse.Builder response = SdkActiveMessage.WeiXinOnlineDotResponse.newBuilder();
		
		ActiveModule_在线礼包 am = ActiveModule_在线礼包.get(pcode);
		if(am == null) {
			send(messageSource, response, Result.ActNoOpen);
			return;
		}
			
		am.updatedot();
		
		send(messageSource, response, Result.Success);
	}

	private void send(MessageSource messageSource, SdkActiveMessage.WeiXinOnlineDotResponse.Builder response, Result result) {
		response.setResult(result.packResult());
		MessageEmitterHandler.getInstance().send(messageSource, response.build());
	}
	
}
